const mysql = require('../db/mysql57');

const faultDao = {
    getAllfault(reqId, uid) {
        let sql = `select
                df.id as id,
                DATE_FORMAT(df.time, '%Y-%m-%d %H:%i:%s') as faultTime,
                df.faultCode as faultCode,
                dt.type as modelSeries,
                d.devID as equipmentId,
                dp.hospital as hospital,
                dp.name as department,
                d.enzymeSolution as enzymeType,
                d.disinfectant as disinfectantType,
                df.description as faultDescription,
                df.is_read as is_read,
                DATE_FORMAT(df.time, '%Y-%m-%d %H:%i:%s') as createdAt,
                DATE_FORMAT(df.updateTime, '%Y-%m-%d %H:%i:%s') as updatedAt
            from DeviceFault as df
            left join Device as d on df.deviceId = d.id
            left join DeviceType as dt on d.deviceTypeId = dt.id
            left join Department as dp on d.departmentId = dp.id
            where df.is_del = ?
            order by df.id desc`;
        let data = [ 'false' ];
        return mysql.sqlExec(sql, data);
    },
    deletefault(reqId, uid, id) {
        let sql = `update DeviceFault set is_del = ? where id = ?`;
        let data = [ 'true', id ];
        return mysql.sqlExec(sql, data);
    },
    readFault(reqId, uid, id) {
        let sql = `update DeviceFault set is_read = ? where id = ?`;
        let data = [ 'true', id ];
        return mysql.sqlExec(sql, data);
    }
};

module.exports = faultDao;